package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.AWechatOfficialAccountUsers;
import com.ruoyi.lock.service.IAWechatOfficialAccountUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公众号用户Controller
 * 
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/lock/wxUsers")
public class AWechatOfficialAccountUsersController extends BaseController
{
    @Autowired
    private IAWechatOfficialAccountUsersService aWechatOfficialAccountUsersService;

    /**
     * 查询公众号用户列表
     */
    @PreAuthorize("@ss.hasPermi('lock:wxUsers:list')")
    @GetMapping("/list")
    public TableDataInfo list(AWechatOfficialAccountUsers aWechatOfficialAccountUsers)
    {
        startPage();
        List<AWechatOfficialAccountUsers> list = aWechatOfficialAccountUsersService.selectAWechatOfficialAccountUsersList(aWechatOfficialAccountUsers);
        return getDataTable(list);
    }

    /**
     * 导出公众号用户列表
     */
    @PreAuthorize("@ss.hasPermi('lock:wxUsers:export')")
    @Log(title = "公众号用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AWechatOfficialAccountUsers aWechatOfficialAccountUsers)
    {
        List<AWechatOfficialAccountUsers> list = aWechatOfficialAccountUsersService.selectAWechatOfficialAccountUsersList(aWechatOfficialAccountUsers);
        ExcelUtil<AWechatOfficialAccountUsers> util = new ExcelUtil<AWechatOfficialAccountUsers>(AWechatOfficialAccountUsers.class);
        util.exportExcel(response, list, "公众号用户数据");
    }

    /**
     * 获取公众号用户详细信息
     */
//    @PreAuthorize("@ss.hasPermi('lock:wxUsers:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return success(aWechatOfficialAccountUsersService.selectAWechatOfficialAccountUsersById(id));
//    }

    /**
     * 新增公众号用户
     */
    @PreAuthorize("@ss.hasPermi('lock:wxUsers:add')")
    @Log(title = "公众号用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AWechatOfficialAccountUsers aWechatOfficialAccountUsers)
    {
        return toAjax(aWechatOfficialAccountUsersService.insertAWechatOfficialAccountUsers(aWechatOfficialAccountUsers));
    }

    /**
     * 修改公众号用户
     */
    @PreAuthorize("@ss.hasPermi('lock:wxUsers:edit')")
    @Log(title = "公众号用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AWechatOfficialAccountUsers aWechatOfficialAccountUsers)
    {
        return toAjax(aWechatOfficialAccountUsersService.updateAWechatOfficialAccountUsers(aWechatOfficialAccountUsers));
    }

    /**
     * 删除公众号用户
     */
    @PreAuthorize("@ss.hasPermi('lock:wxUsers:remove')")
    @Log(title = "公众号用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aWechatOfficialAccountUsersService.deleteAWechatOfficialAccountUsersByIds(ids));
    }
}
